#include "proxypool.h"

ProxyPool::ProxyPool(QObject *parent) : QObject(parent)
{
    // 示例代理列表，实际应用中请替换为您的代理地址列表
//    proxies << "200.54.194.13:53281"
//            << "188.165.252.198:57576"
//            << "20.206.106.192:80"
//            << "58.234.116.197:8197"
//            << "  103.177.235.132:84"
//            << "153.19.91.77:80"
//            << "23.227.38.198:80"
//            << "72.217.158.202:4145"
//            << "178.115.230.243:8080"
//            << "103.58.95.5:8080"
//            << "51.161.56.52:80"
//            << "5.181.171.134:8085";
}

ProxyPool::~ProxyPool() {}

QString ProxyPool::getNextProxy()
{
    if (proxies.isEmpty()) {
        qDebug()<< "Proxy pool is empty!";
        return {};
    }

    QString proxy = proxies.takeFirst();
    proxies.append(proxy); // 将代理地址放回列表末尾，实现循环使用
    return proxy;
}

void ProxyPool::clear()
{
    proxies.clear();
}

void ProxyPool::updateProxyList(const QList<QString> &newProxies)
{
    //需要增加一个代理有效性的验证，有效的才加入
    proxies = newProxies;
    qDebug()<<"ProxyPool size"<<proxies.size();
    emit proxyListUpdated();
}
